<style lang="less">
  @import '../../styles/common.less';

</style>
<template>
  <div>
    <Button type="primary" size="large" @click="add">添加banner图</Button>
    <Table border :columns="columns" :data="data" style="margin-top:20px;"></Table>
  </div>
</template>

<script>
    export default {
        name: "banner",
        data(){
          return{
            columns: [
              {
                title: '编号',
                key: 'id'
              },
              {
                title: '标题：',
                key: 'bannerTitle'
              },
              {
                title: '描述：',
                key: 'bannerDesc'
              },
              {
                title: '图片：',
                key: 'bannerImg',
                render:function (h,params) {
                  return h('div', [
                    h('img', {
                      attrs: {
                        src: params.row.bannerImg
                      },
                      style: {
                        width: '150px',
                        height: '70px'
                      }
                    }),
                  ]);
                }
              },
              {
                title: '操作',
                key: 'action',
                width: 180,
                align: 'center',
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.show(params.index)
                        }
                      }
                    }, '查看'),
                    h('Button', {
                      props: {
                        type: 'primary',
                        size: 'small'
                      },
                      style: {
                        marginRight: '5px'
                      },
                      on: {
                        click: () => {
                          this.edit(params.index)
                        }
                      }
                    }, '修改'),
                    h('Button', {
                      props: {
                        type: 'error',
                        size: 'small'
                      },
                      on: {
                        click: () => {
                          this.remove(params.index)
                        }
                      }
                    }, '删除')
                  ]);
                }
              }
            ],
            data: [

            ]
          }
        },
        methods:{
          add(){
            this.$router.push({
              name: 'banner_mod'
            });
          },
          show (index) {
            this.$Modal.info({
              title: 'banner明细',
              content: `标题：${this.data[index].bannerTitle}<br>
                        描述：${this.data[index].bannerDesc}<br>
                        图片：${this.data[index].bannerImg}<br>`
            })
          },
          edit(index){
            this.$router.push({
              name: 'banner_mod',
              query:{id:this.data[index].id}
            });
          },
          remove (index) {
            this.$http.get('/school/delBanner?id='+this.data[index].id).then(res => {
              this.$Message.success('删除成功!');
              this.data.splice(index, 1);
            });
          }
        },
      mounted () {
        this.$http.get('/school/getBanner').then(res =>{
          this.data = res.data.data;
        })
      }
    }
</script>

<style scoped>

</style>
